import java.util.ArrayList;

public abstract class BHTSelector implements BHTNode {
	private ArrayList<BHTNode> children;
	private BHTNode parent;
	
	public BHTSelector() {
		
	}
	
	public BHTSelector(ArrayList<BHTNode> children, BHTNode parent) {
		this.children = children;
		this.parent = parent;
	}
	
	public boolean isLeaf() {
		// selector node can't be a leaf node
		return false;
	}
	
	public ArrayList<BHTNode> getChildren() {
		return children;
	}
	public void addChild(BHTNode child) {
		children.add(child);
	}
	public BHTNode getParent() {
		return parent;
	}
	public void setParent(BHTNode parent) {
		this.parent = parent;
	}

	public TerminationCode executeBehaviour() {
		TerminationCode code = chooseAndExecuteChild();
		switch (code) {
		case SUCCEED:
			return TerminationCode.SUCCEED;
		case FAIL_CLEAN:
			// Choose another child
			return executeBehaviour();
		case FAIL_ERROR:
			// propagate the error
			return code;
		default:
			// niet gebruikt
			return code;
		}
	}
	
	public abstract TerminationCode chooseAndExecuteChild();

}
